/**
 * file for administration.php
 */



function confirm_screen() {
	// check if there is at least one option enabled
	try {
		var selected_entries = 0;
		var i = 0;
		while(true) {
			i++;
			if (document.getElementById("option"+i).checked == true) {
				selected_entries++;
			}
		}
	} catch(e) {
		// nothing to do here
	}
	if (selected_entries == 0) {
		alert(text_admin_selection);
		return false;
	}

	if (confirm(text_admin_safety) == true) {
		// hide update button to avoid further clicks
		dojo.byId("admin_buttons").style.display = "none";
		dojo.byId("messageArea").style.display  = "none";
		return true;
	} else {
		return false;
	}
}

function download_data(type) {
	if (type < 1 || type > 3) return;
	
	// create config.php and attributes.php
	var url_param;
	switch(type) {
		case 1: 
			dojo.byId("refresh_button").style.display  = "none";
			dojo.byId("refresh_galaxy_button").style.display  = "none";
			dojo.byId("refresh_stats_button").style.display  = "none";
			url_param = "reload_all";
			break;
		
		case 2: dojo.byId("refresh_galaxy_button").style.display  = "none"; url_param = "reload_galaxy"; break; 
		case 3: dojo.byId("refresh_stats_button").style.display  = "none"; url_param = "reload_stats"; break;
	}
	dojo.byId("refresh_done").style.display = "none";
	dojo.byId("refresh_failed").style.display = "none";
	dojo.byId("refresh_loading").style.display = "";
	
	var xhrArgs = {
		url : "ajax/ajax_administration.php?type="+url_param,
		handleAs : "json",
		load : function(jsonData) {
			if (jsonData.messages != null) {
				showMessages(jsonData.messages, "../images", false);
			}
			dojo.byId("refresh_loading").style.display = "none";

			if (jsonData.result == true) {
				dojo.byId("refresh_done").style.display = "";
			} else {
				dojo.byId("refresh_failed").style.display = "";
			}

		},
		error : function(error) {
			console.log("Error:");
			console.log(error);
		}
	}
	dojo.xhrPost(xhrArgs);
}